var LOGGED = false;
var DATABASES = new Array();
var LEFTMENUOPEN = false;

var MYSQL_HOST = null;
var MYSQL_USER = null;
var MYSQL_PASS = null;


var basic = {
	/* Defines */
	isie:document.all?true:false,

	/* Functions */
	setContent:function(content)
	{
		$('#divMainContent').html(content);
	},

	clearContent:function()
	{
		$('#divMainContent').empty();
	},

	setContentWait:function()
	{
		basic.setContent(
			'<div class="fontTahoma size10 colorBlack" style="padding:10px;">'+
				'<img src="images/loader.gif" align="top" border="0"> <i>Working, please wait...</i>'+
			'</div>'
		);
	},

	onload:function()
	{
		if(!LOGGED)
		{
			server.request(
				server.funcs.isLogged,
				function(data)
				{
					if(data.Logged)
					{
						LOGGED = true;
						basic.start();
					}
					else
					{
						boxes.login.show();
					}
				}
			);
		}
	},

	start:function()
	{
		$('#mainContainer').fadeIn('slow');
		server.requests.getBasicData();
		editor.draw('SELECT * FROM `table`');
		//$('#divContent').rte("css url", "");
	},

	scroll:function()
	{
		return {left:document.body.scrollLeft,top:document.body.scrollTop};
	},
	
	getPageSize: function()
	{
		var xScroll, yScroll;
		if(window.innerHeight && window.scrollMaxY)
		{	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if(document.body.scrollHeight > document.body.offsetHeight)
		{
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else
		{
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if(self.innerHeight)
		{
			if(document.documentElement.clientWidth)
			{
				windowWidth = document.documentElement.clientWidth; 
			}
			else
			{
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientHeight)
		{
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if(document.body)
		{
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	

		if(yScroll < windowHeight)
		{
			pageHeight = windowHeight;
		}
		else
		{ 
			pageHeight = yScroll;
		}

		if(xScroll < windowWidth)
		{	
			pageWidth = xScroll;		
		}
		else
		{
			pageWidth = windowWidth;
		}
		return [pageWidth,pageHeight];
	},

	setCookie:function(name, value, expires)
	{
		if('undefined' == typeof expires || null == expires)
		{
			var expires = new Date();
			expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 30));
		}
		document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
	},

	getCookie:function(name)
	{
		var dc = document.cookie;
		var cname = name + "=";
		
		if (dc.length > 0)
		{
			begin = dc.indexOf(cname);
			if(begin != -1) 
			{
				begin += cname.length;
				end = dc.indexOf("", begin);
				if(end == -1)
				{
					end = dc.length;
				}
				return unescape(dc.substring(begin, end));
			}
		}
		return null;
	},

	resizeMainContent:function()
	{
		bodySize = basic.getPageSize();
		$('#divMainContent').css(
			{
				'left':'25px',
				'top':'125px',
				'width':bodySize[0]-50,
				'height':bodySize[1]-150
			}
		);
		$('#divLeftMenu').css({'height':bodySize[1]-150});
		$('#divLeftMenuContent').css({'height':bodySize[1]-170});
	}
};

window.onresize = basic.resizeMainContent;